﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FridayPractice
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Register_Click(object sender, EventArgs e)
        {
            string sql = "";
            bool result = false;
            string id = ID.Text.ToString();
            string pwd = PWD.Text.ToString();
            if (id == "" || pwd == "")
            {
                MessageBox.Show("用户名或密码不能为空", "非空验证 ");
            }
            else
            {
                //判断改用户是否已存在
                sql = string.Format("select * from Admin1 where UserID='{0}'", id);
                SqlDataReader dr = DBHelper.Select(sql);
                while (dr.Read())
                {
                    MessageBox.Show("该用户已存在！！");
                    result = true;
                    break;
                }
                dr.Close();
                if (result != true)
                {
                    sql = string.Format("insert into Admin1 (UserID,UserPWD) values('{0}','{1}')", id, pwd);
                    bool reader = DBHelper.Register(sql);
                    MessageBox.Show("成功!", "注册成功");
                }
            }
        }
    }
}
